package com.copm.demonstrationsystem.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;

/**
 * @author chuyunfei
 * @date: 2018/4/1
 * @description: spring容器的配置类
 */
@Configuration
public class RootConfig {

    /**
     * 1、为开发环境配置c3p0连接池对象
     * @return
     * @throws PropertyVetoException
     */
    @Bean
    @Qualifier("dataSource")
    @Profile("dev")
    public DataSource dataSource() throws PropertyVetoException{
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setJdbcUrl("jdbc:mysql:///demonstration_system?useUnicode=true&characterEncoding=utf-8&useSSL=false");
        dataSource.setDriverClass("com.mysql.jdbc.Driver");
        dataSource.setUser("root");
        dataSource.setPassword("cyteam");
        dataSource.setMinPoolSize(2);
        dataSource.setMaxPoolSize(10);
        dataSource.setInitialPoolSize(2);
        dataSource.setAcquireIncrement(4);
        dataSource.setMaxStatements(100);
        dataSource.setMaxIdleTime(300000);
        dataSource.setAcquireRetryDelay(1000);
        return dataSource;
    }
}
